#!/bin/bash

echo "Creating new user request"

function usage () {
    echo "Usage: ./$0 \"Name-Of-User\" <url>"
}

if [[ $# -eq 0 ]]; then
    # using defaults
    URL="http://dabbler.herokuapp.com/api/v1/users/"
    EMAIL="john.doe@norge.no"
    NAME="John Doe"
else
    if [[ ! $# -eq 3 ]]; then
        usage
        exit 0
    fi
    URL=$3
    EMAIL=$2
    NAME=$1
fi

echo "Name of user: $NAME"
echo "E-mail: $EMAIL"
echo "URL: $URL"

CMD="curl -X POST --data 'name=$NAME&mail=$EMAIL' $URL"
echo "$CMD"
eval $CMD
